package com.eng.carro;

import java.io.Serializable;
import java.util.Calendar;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.eng.carro.entities.DeliveryPlace;
import com.eng.carro.entities.DeliveryRoute;
import com.eng.carro.entities.Order;
import com.eng.carro.entities.User;
import com.eng.carro.services.DeliveryRouteService;
import com.eng.carro.services.OrderService;
import com.eng.carro.services.UserService;

@ManagedBean( name = "helloMB" )
@SessionScoped
public class Hello implements Serializable {

  private static final long serialVersionUID = 8017158321425015722L;
  
  private String name = "Projeto do Carro!!!!";

  @EJB DeliveryRouteService userService;
  @EJB OrderService orderService;
  
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
    try {
      DeliveryRoute route = new DeliveryRoute();
      route.setDeliveryPlace(new DeliveryPlace(1));
      route.setRfId("RFID01");
      route.setValue("Teste");
      
      userService.makePersistent(route);
      
      Order order = new Order();
      order.setCar(1);
      order.setDate(Calendar.getInstance());
      order.setDeliveryPlace(new DeliveryPlace(1));
      order.setDescription("Teste");
      order.setPriority(1);
      order.setStatus(0);
      
      orderService.makePersistent(order);
      
//      System.out.println(.getDefaultPlace().getLocal());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
}
